export default {
    get:function(key){
        // 获取数据
        // 获取时间戳
        let time = localStorage.getItem(key+'_time');
        if(time==-1){
            return localStorage.getItem(key);
        }else{
            let now = new Date().getTime() / 1000;
            if(time - now <= 0){
                localStorage.removeItem(key);
                localStorage.removeItem(key+'_time');
                return null;
            }
            return localStorage.getItem(key);
        }
        
    },
    set:function(key,value,time=-1){
        // time=-1表示永久存储
        let now = new Date().getTime() / 1000;
        if(time > 0){
            time = time  + now;
        }
        localStorage.setItem(key+'_time',time)
        localStorage.setItem(key,value);
    },
    remove:function(key){
        localStorage.removeItem(key);
        localStorage.removeItem(key+'_time');
    },
    clearAll:function(){
        localStorage.clear();
    }
}